package com.haoxuewa.controller;

import com.haoxuewa.config.listener.OnLineCountListener;
import com.haoxuewa.service.UserService;
import com.haoxuewa.service.VisitQuantityService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/statistics")
public class VisitQuantityController {

    private final VisitQuantityService visitQuantityService;

    @Autowired
    public VisitQuantityController( VisitQuantityService visitQuantityService) {
        this.visitQuantityService = visitQuantityService;
    }

    //统计一周内在线人数情况
    @GetMapping("/getVisitCountOfWeek")
    public String visitCountOfWeek() {
        JSONObject jsonObject = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
        int weekOfDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        int[] result = visitQuantityService.weekVisited(weekOfDay);
        jsonObject.put("visitCount", result);
        return jsonObject.toString();
    }

    //统计当天用户在线情况
    @GetMapping("/getTodayOnlineCount")
    public String toDayOnlineCount() {
        JSONObject jsonObject = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
//        int hour_index = calendar.get(Calendar.HOUR_OF_DAY) / 4;
//        int[] result = new int[hour_index];
//        System.arraycopy(OnLineCountListener.realTimeOnLineCountList, 0, result, 0, hour_index + 1);
//        int[] result = new int[]{69,92,83,29,58,77};
        jsonObject.put("dayOfCount", OnLineCountListener.realTimeOnLineCountList);
        return jsonObject.toString();
    }


}
